/**
 * 
 */
package com.android.calldelay;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.util.Log;
import android.widget.Toast;

/**
 * @author INVEERA
 * 
 */
public class OnAlertReceave extends BroadcastReceiver {

	private static final String LOG_TAG = "OnAlertReceave";

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.content.BroadcastReceiver#onReceive(android.content.Context,
	 * android.content.Intent)
	 */
	@Override
	public void onReceive(Context context, Intent intent) {
		// calling for initiating the call delay
		Log.d(LOG_TAG, "We are from setup::::");

		SharedPreferences setting = context.getSharedPreferences(
				AppInfo.APP_PREF, 0);

		int alertTime = setting.getInt(AppInfo.KEY_TOTAL_ALERT_TIME, 0);

		int mins = alertTime / 60;
		int seconds = alertTime - mins * 60;

		Toast.makeText(context,
				"The call will start after " + mins + "." + seconds+"min",
				Toast.LENGTH_SHORT).show();
		/*
		 * Panga mat lena
		 */
		Notification notification = new Notification(
				android.R.drawable.ic_popup_reminder, // Icon to use
				"Standby Call", // Text
				System.currentTimeMillis() // When to display - i.e. now
		);
		notification.flags |= Notification.FLAG_AUTO_CANCEL;

		PendingIntent pi = PendingIntent.getActivity(context, 0, new Intent(
				context, MainActivity.class), 0);

		// Add to the Notification
		notification.setLatestEventInfo(context, "Standby Call", // Title of
																	// detail
																	// view
				"The call will start after " + mins + "." + seconds+"min", // Text on
																		// detail
																		// view
				pi);
		// Display the Notification
		NotificationManager nm = (NotificationManager) context
				.getSystemService(Context.NOTIFICATION_SERVICE);
		nm.notify(1, notification);
	}
}
